package jman.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Vote_User1Dao {
	public boolean add(int vote_id,int user_id,int count){
		boolean flag=false;
		Dao d=new Dao();
		d.start();
		String sql="insert into vote_user1 (vote_id,user_id,count) values ("+vote_id+","+user_id+","+count+")";
		flag=d.add(sql);
		d.close();
		return flag;
	}
	public boolean update(int vote_Id,int user_Id){
		boolean flag=false;
		Dao d=new Dao();
		d.start();
		String sql="update vote_user1 set count=count+1 where vote_id="+vote_Id+" and user_id="+user_Id;
		flag=d.update(sql);
		d.close();
		return flag;
	}
	public int getUser_IdFinally(int vote_Id) throws SQLException{
		int id=0;
		Dao d=new Dao();
		d.start();
		String sql="select * from vote_user1 where vote_id="+vote_Id+" order by count desc limit 1";
		ResultSet rs=d.read(sql);
		while(rs.next()){
			id=rs.getInt(3);
		}
		d.close();
		return id;
	}
}
